/**
 * FormData 参数格式化
 * @param data 参数对象
 * @returns
 */
export function formdata(data) {
  if (data instanceof FormData) return data
  var formdata = new FormData()
  for (let key in data) {
    if (typeof data[key] === 'object' && !(data[key] instanceof File)) {
      formdata.append(key, JSON.stringify(data[key]))
    } else {
      formdata.append(key, data[key])
    }
  }
  return formdata
}
/**
 * queryObject转queryString
 * @param {Object} json
 * @returns {Array}
 */
export function getQueryString(json) {
  if (!json) return ''
  return Object.keys(json)
    .map((key) => {
      if (json[key] === undefined) return ''
      return encodeURIComponent(key) + '=' + encodeURIComponent(json[key])
    })
    .join('&')
}
